package javabase.schoolwork.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author fance
 * @date 2018/6/5 9:19
 */
public class Sum {
    public static final String DBDRIVER = "com.mysql.jdbc.Driver";
    public static final String DBURL = "jdbc:mysql://localhost:3306/test";
    public static final String DBUSER = "root";
    public static final String DBPASS = "123456";

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
//        Class.forName(DBDRIVER);
//        Connection connection = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
        String sql1 = "select * from user";
       String sql2 = "insert into user(name,password,age,sex,birthday) " +
                " values ('selina','123456',18,null,'2018-06-21')";
        String sql3 = "delete from user where id = 1";
       /*  Statement statement = connection.createStatement();
        ResultSet resultSet =  statement.executeQuery(sql);
        while (resultSet.next()) {
            System.out.println(resultSet.getInt("id"));
            System.out.println(resultSet.getString("name"));
            System.out.println(resultSet.getString("password"));
            System.out.println(resultSet.getInt("age"));
            System.out.println(resultSet.getDate("birthday"));
        }
        statement.close();
        resultSet.close();*/


        ResultSet resultSet =   DBUtil.select(DBUtil.getConnection(),sql1);
        while (resultSet.next()) {
            System.out.println(resultSet.getInt("id"));
            System.out.println(resultSet.getString("name"));
            System.out.println(resultSet.getString("password"));
            System.out.println(resultSet.getInt("age"));
            System.out.println(resultSet.getDate("birthday"));
        }

        DBUtil.update(DBUtil.getConnection(),sql2);
        DBUtil.update(DBUtil.getConnection(),sql3);
        /*String sql = "insert into user(name,password,age,sex,birthday) " +
                " values (?,?,?,?,?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,"xiaohei");
        preparedStatement.setString(2,"123");
        preparedStatement.setInt(3,20);
        preparedStatement.setString(4,"F");
        preparedStatement.setDate(5,new Date(32454235));
        preparedStatement.executeUpdate();
        preparedStatement.close();*/





        //connection.close();
    }
}
